<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
		<meta name="format-detection" content="telephone=no" />
		<title>首页</title>
		<link rel="stylesheet" type="text/css" href="../c/aui.css" />
		<style>
			.f {
            position: fixed;
            bottom: 0;
            left: 0;
            width: 100%;
            color: #fff;
            padding: 0 0.75rem;
            font-size: 0.75rem;
            background: #020202
        }
        .f div:last-child {
            color: #FF2C55;
        }
        .f img{
          width: 1.2rem;
        }
    </style>
	</head>
	<body>
		<div class="f aui-card-list-footer" id="sx-footer">
			<div tapmode onclick="_close()">取消</div>
			<div tapmode onclick="reset();"><img src="../i/reset.png" /></div>
			<div tapmode onclick="save()">确认</div>
		</div>
	</body>
	<script type="text/javascript" src="../j/api.js"></script>
	<script type="text/javascript">
		var FNImageClip
		apiready = function() {
			api.parseTapmode();
			FNImageClip = api.require('FNImageClip');
			allowEdit();
		}

		// 裁剪头像
		function allowEdit() {
			$api.fixTabBar($api.byId('sx-footer'))
			var f = $api.offset($api.byId('sx-footer')).h;
			FNImageClip.open({
				rect: {
					x: 0,
					y: 0,
					w: api.winWidth,
					h: api.winHeight - f
				},
				srcPath: api.pageParam['img'],
				isMinWidth: false,
				isMinHeight: false,
				isHideGrid: true,
				style: {
					mask: 'rgba(0, 0, 0, 0.7)',
					clip: {
						w: api.winWidth-15,
						h: api.winHeight-50,
						x:5,
						y: 5,
						borderColor: '#f00',
						borderWidth: 1,
						appearance: 'rectangle'

					}
				},
				fixedOn: api.frameName
			}, function(ret, err) {
				if (ret) {
					console.log(JSON.stringify(ret));
				} else {
					console.log(JSON.stringify(err));
				}
			});
		}

		function save() {
			FNImageClip.save({
				destPath: 'fs://www_suxiangw_com/qq1424445608.png',
				copyToAlbum: false,
				quality: 1
			}, function(ret, err) {
				if (ret) {
					if (ret.destPath) {
						_loading();
						_qiniu(ret.destPath, function(ret, err) {
							if (ret.status) {
								if (ret.oper == "complete") {
									//上传成功后组装访问路径，或直接访问文档
									var img = ret.info.key;
									var jinbi = localStorage.getItem("jinbi");
									var id = localStorage.getItem("id");
									_ajax1('task/add', function(ret, err) {
										// console.log(JSON.stringify(ret));
										if (ret && ret.ret!=undefined) {
											_alert(JSON.stringify(ret.ret))
											_msg(ret.ret ? ret.ret : ret.err);
											if (ret.ret) {
												api.closeWin({
													name: 'img'
												});
												api.execScript({
													name: 'renwu_adds',
													frameName: 'renwu_adds',
													script: 'img_name("' + img + '")'
												});
												_zhen();
												_close();
											}
										} else {
											_alert(JSON.stringify(ret.err))
										}
										_loadingCloes();
										_heibai();
									}, {
										content: img,
										task_id: id,
										jinbi: jinbi
									})
								} else if (ret.oper == "progress") {
									//上传过程中获取进度数据
								}
							} else {
								_loadingCloes();
								console.log(JSON.stringify(err));
							}
						});
					}
				} else {
					_loadingCloes();
					console.log(JSON.stringify(err));
				}
			});
		}

		function reset() {
			FNImageClip.reset();
		}
	</script>

</html>
